///////////////////////////////////////////////////////////
///////////////// Have an itch? Scratch it! ///////////////
///////////////////////// SCRATCH /////////////////////////
/////////////////////  A MUD  Server   ////////////////////
///////////////////// By: Jared Devall ////////////////////
/////////////////////      Thanks:     ////////////////////
/////////////////////  DIKU/Merc/ROM   ////////////////////
///////////////////// Aetas/Deus Gang  ////////////////////
/////////////////////       Beej       ////////////////////
///////////////////////////////////////////////////////////

#ifndef __WORLD_H_
#define __WORLD_H_

#include <stdlib.h>
#include "avatar.h"
#include "timer.h"
#include "smysql.h"
#include <list>
#include <queue>

enum BROADCAST_TYPE { ALL, WCONNECTED };
class World {
	bool         _worldExists;
	typedef std::priority_queue<Timer *, std::vector<Timer *>, timer_less> TimerQueue;	
	
	void         FlushOutput( void );
	void         UpdateAvatars( void );
	void         KillFlaggedAvatars( void );
	void         HandleInput( void );
	void         UpdateTimers();
	void         Schedule( Timer * );
	void         Unschedule( Timer * );
	TimerQueue   _timers;
	
	public:
	Avatar *     FindAvatar ( const std::string & );
	void         Broadcast( const std::string &, BROADCAST_TYPE );
	void         Exist( const std::string &, int port, bool copyover );
	void         Die( void );
	void         Copyover( void );
	void         CopyoverRecovery( void );
	void         Monitor( void );
	static World &Instance();	

	std::list< Avatar * > _avatarList;
};

// Our singleton instance
inline World &World::Instance() {
	static World instance;
	return instance;
}
#endif
